(label Refresh 3d View) Moving the Object Around in the World
The script contained in this frame refreshes the coordinates of the points in the 3D view when one of the dragable points in the editing view is being dragged.
Each of the draggable points contain a button which gives variable:"drag" a value of 1 when pressed (refer to Fig04 {DragVertex , Page ??).
If drag has a value of 1, the script in this frame is called from the main looping script ( frame4)ItΓÇÖs important to note that all the scripts up to this point have dealt with setting static point coordinates for the vertices that makes up the 3D object (frame 2), and that the rotation values (Variable: "Yangle" and Variable: "Xangle") set in frame 6 ("Mousetracking") is used to rotate the "world" in frame 7("3d Calc") and not the actual "object". What weΓÇÖre actually doing is orbiting the ΓÇÿcameraΓÇÖ around the ΓÇÿ[worldΓÇÖsΓÇÖ center point rather than rotating the ΓÇÿobjectΓÇÖ. The ΓÇÿobjectΓÇÖ has a relationship to the ΓÇÿworldΓÇÖ that is set through its individual point coordinates. To move the object or its individual vertices around in the world we need additional calculations to set new values for its x, y and z co-ordinates (the ones initially set in frame 2).
Also note that the basic 3D engine has already been covered in frame 7 and that frames 8 and 9 deal with the added feature of changing coordinates of the individual points on the fly. In fact, if you delete frame 8 and 9 all together youΓÇÖll still be left with a fully functional 3D engine, which allows you to set the initial coordinates in frame 2 and still be able to rotate the view.
IΓÇÖve included the last two frames to illustrate a method of moving the points around within their ΓÇÿworldΓÇÖ, which opens up possibilities for numerous applications. IΓÇÖll touch on these a little further down.In my example, I wanted to play with the idea of a mini-3D application that would allow the user to drag points around in an editing view to create his/her own 3D forms (albeit very simple). This application is so specific that I doubt whether you would want to duplicate it. For this reason IΓÇÖm going to move through this quite quickly, focusing on the general concept. IΓÇÖll extract a few key points towards the end of this chapter.
The movie starts with the object being viewed along the Z-axis and the editing view also showing the same view. The view in the 3d window is set through the combined rotation angles on the X and Y axis ( Variable:Xangle and Variable:Yangle ). If we recap, these angles were set by the position of "/TrailerObj" (frame 6) which in turn, gets its position from "/Mouseloc". In frame 3 we set the X and Y coordinate of "/Mouseloc" to 0. In other words, when the movie starts, the rotation value of both variables: "Xangle" and "Yangle" will be 0 which is the view along the Z axis.
To change the view when one of the X,Y or Z buttons are pressed, I simply set the X and Y position of "/Mouseloc", which usually represent the mouse position, to a new coordinate and "/TrailerObj" follows setting new values for Variables: Xangle and Yangle. The coordinates of "/Mouseloc" for the 3 views are as follows:
Along X- axis: "/mouseloc" X position = 90 and "/mouseloc" Y position = 0
Along Y- axis: "/mouseloc" X position = 0 and "/mouseloc" Y position = 90
Along Z- axis: "/mouseloc" X position = 0 and "/mouseloc" Y position = 0
The appropriate position for "/Mouseloc" is set as part of the action on each one of the X,Y anf Z buttons in the top right-hand corner.
So, now that we know how to rotate the view to the appropriate angle, the following rules apply:
When editing along the Z-axis: the Horizontal (X) and Vertical (Y) distance of "/dragpoint" away from the center point of the editing view, would correspond to the distance of the X and Y coordinates of "/Vertex" away from the centre point of the world.
When editing along the X-axis: the Horizontal (X) and Vertical (Y) distance of "/dragpoint" away from the center point of the editing view, would correspond to the distance of the Z and Y coordinates of "/Vertex" away from the centre point of the world.
When editing along the Y-axis: the Horizontal (X) and Vertical (Y) distance of "/dragpoint" away from the centrepoint of the editing view, would correspond to the distance of the Z and X coordinates of "/Vertex" away from the centre point of the world.
The X, Y and Z buttons each contains a script that looks like this:
On (Press)
Set Variable: "axisx" = "z"
Set Variable: "axisy" = "y"
Set Variable: "Yaxisneg" = 1
Set Property ("mouseloc", X Position) = 90
Set Property ("mouseloc", Y Position) = 0
Begin Tell Target ("xyz")
Go to and Stop ("x")
End Tell Target
Call ("Refresh Editing View")
End On
When the user presses one of these buttons, Variable: "AxisY" is set to a value either "x", "y" or "z". This tells the movie which axis of "/Vertex" should be affected when manipulating the Y position of "/dragpoint" for each view. It also sets Variable: "AxisX", which does the same except that it tells the movie which axis to affect on manipulating the X position of "/dragpoint". It also sets Variable: "Yposneg" to ΓÇö1 if the Y-Axis is selected. This simply mirrors the view when editing on the Y-Axis ( without this the editing view along the Y-Axis would appear upside down). It also gives "/Mouseloc" a new position, as already explained above. This rotates view to the new view.
The script in frame 8 looks like this:
Set Variable: "dc" = 0
Loop While (dc < 9)
Set Variable: "dc " = dc + 1
Set Variable: AxisY&dc = (getproperty("DragVertex"&dc,_Y)-EditingCenterY)*Yaxisneg
Set Variable: AxisX&dc = getproperty("DragVertex"&dc,_X)-EditingCenterX
The script is looped nine times (once for each point). If the "Z button" was the last one to be pressed, you will be editing along the Z-axis, according to our rule mentioned above, Variable: "axisY" will have the value of "y" and Variable: "AxisX" will have "x" as its value. Variable: "EditingCenterY" and "EditingCenterX" represents the coordinates of the centre of the editing view.
After the script has looped nine times:
Variable: "y1" will be set to the distance "/dragpoint1" is away from the centre of the editing view on the Y-axis.
Variable: "x1" will be set to the distance "/dragpoint1" is away from the centre of the editing view on the X-axis.
Variable: "y2" will be set to the distance "/dragpoint2" is away from the centre of the editing view on the Y-axis.
Variable: "x2" will be set to the distance "/dragpoint2" is away from the centre of the editing view on the X-axis.etc
The rest of the script on this frame is simply responsible for updating the lines that connect "/dragpoint1" to "/dragpoint9". This script is similar to the one used in frame 7 to scale the lines between the individual vertices in the 3D object.
Frame 9: (label: Refresh Editing View) Refreshing the Editing View
The script contained in this frame refreshes the editing view that the user sees when they press one of the XYZ buttons and is called from the script within these buttons.